#include <stdio.h>

int main(int argc, char const *argv[])
{
    int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    int year = 0, month = 0, day = 0, sum = 0;

    while (scanf("%d %d %d", &year, &month, &day)!=EOF)
    {
        if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
        {
            days[1] = 29;
        }

        if (month == 1)
        {
            printf("%d\n", day);
        }
        else
        {
            for (size_t i = 0; i < month - 1; i++)
            {
                sum += days[i];
            }
            printf("%d\n", sum + day);
        }
    }

    return 0;
}
